<?php

/**
 * report actions.
 *
 * @package    manageet
 * @subpackage report
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class reportActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    return sfView::SUCCESS;
  }
  
  public function executeGetLoadDistribution(sfWebRequest $request)
  {
    $this->getResponse()->setHttpHeader('Content-Type', 'application/xml; charset=utf-8');
    
    $day = $this->getRequest()->getParameter('day', null);
    $memid = $this->getRequest()->getParameter('memid', null);
    $reports = ReportAnalyzer::getReports($day, $memid);
    $dist = ReportAnalyzer::getLoadDistribution($reports);
    if ($dist == null) {
      return $this->renderText('<graph></graph>');
    }
    $xml = new XmlChartPie();
    $xml->addSingleSet(ReportAnalyzer::getDistSet($dist,'hours', '/report/getItems'));

    return $this->renderText($xml->render());
    
  }
  
  public function executeGetItems(sfWebRequest $request)
  {
    $this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
    $day = $this->getRequest()->getParameter('day', null);
    $memid = $this->getRequest()->getParameter('memid', null);
    $cat = $this->getRequest()->getParameter('category', '');
    $items = ReportAnalyzer::getItems($cat, $day, $memid);
    return $this->renderText(json_encode($items));
  }

}
